<template>
	<div>
		<!--start 头部-->
		<!--<div class="sreePublic">
  		<div id="" style="text-align: center;">
  			<em class="iconfont" @click="$router.push({path:'/my'})">&#xe61f;</em>
  		</div>
			{{vue_header_title}}
  	</div>-->
		<!--start 头部-->
		<!--start content-->
		<div class="content myOrder">
			<Tabs v-model="tabName" @on-click="vFun_heightAuo" ref='tabWrap'>
				<Tab-pane label="全部" name="name1" ref='name1'>
					<router-view name="wx"></router-view>
					<!--<wx-list :tabs_type="vue_tabs_item"></wx-list>-->
				</Tab-pane>
				<Tab-pane label="待付款" name="name2" ref='name2'>
					<router-view name="unpaid"></router-view>
					<!--<unpaid-list :tabs_type="vue_tabs_item"></unpaid-list>-->
				</Tab-pane>
				<Tab-pane label="待收货" name="name3" ref='name3'>
					<router-view name="waiting"></router-view>
					<!--<waiting-list :tabs_type="vue_tabs_item"></waiting-list>-->
				</Tab-pane>
				<Tab-pane label="已完成" name="name4" ref='name4'>
					<router-view name="finish"></router-view>
					<!--<finish-list :tabs_type="vue_tabs_item"></finish-list>-->
				</Tab-pane>
				<Tab-pane label="已取消" name="name5" ref='name5'>
					<router-view name="canc"></router-view>
					<!--<canc-list :tabs_type="vue_tabs_item"></canc-list>-->
				</Tab-pane>
			</Tabs>
		</div>
		<!--end content-->
    <vue-footer></vue-footer>
	</div>
</template>

<script>
	import { Toast } from 'mint-ui'; //引入弹框
  import vueFooter from '../../components/footer/footer';     //引入底部
	import wxList from '../../components/orderListComponents/wxListComponents'; //引入全部订单的List
	import unpaidList from '../../components/orderListComponents/unpaidListComponents'; //引入待付款订单的List
	import waitingList from '../../components/orderListComponents/waitingListComponents'; //引入待收货订单的List
	import finishList from '../../components/orderListComponents/finishListComponents'; //引入已完成订单的List
	import cancList from '../../components/orderListComponents/cancListComponents'; //引入已取消订单的List
	export default {
		components: {
			wxList,
			unpaidList,
			waitingList,
			finishList,
			cancList,
      vueFooter
		},
		data() {
			return {
				tabName: 'name1',
				vue_header_title: '我的订单', //头部title
				setHeight: 0,
				vue_tabs_item: null,
				vue_urlNow: window.location.href,
			}
		},
		methods: {
			vFun_heightAuo(name) {
				this.vue_tabs_item = name;
			},
			weixinPayment() {
				var weixinCode = "";
				var notifyUrl = "";
				if(this.vue_urlNow.indexOf("?code=") != -1) { //如果是微信登录，则链接中包含"?code="
					var num = this.vue_urlNow.indexOf("?");
					var rootUrl = this.vue_urlNow.substr(0, num);
					this.vue_urlNow = this.vue_urlNow.substr(num + 1); //取得所有参数   stringvar.substr(start [, length ]
					var arr = this.vue_urlNow.split("&"); //各个参数放到数组里
					var par = arr[0];
					var num2 = par.indexOf("=");
					weixinCode = par.substring(num2 + 1, par.length);

					var paramPos = this.vue_urlNow.indexOf("#");
					if(paramPos != -1) {
						notifyUrl = this.vue_urlNow.substring(0, paramPos) + "v3/sale/orders/orderList";
					}

					if(weixinCode != "" && weixinCode != undefined) { //微信登录
						var orderCode = localStorage.getItem("orderCode");
						if(orderCode != undefined && orderCode != "") {
							this.axios({
								method: "GET",
								url: "/v3/sale/orders/" + orderCode
							}).then((res) => {
								var list = res.data.saleOrderGoodsDataList;
								var subject = "";
								//var productCode = "";
								var body = "";
								var totalAmout = 0;
								if(list != null && list.length > 0) {
									for(var i = 0; i < list.length; i++) {
										var orderGood = list[i];
										subject += orderGood.goodsName + ",";
										//	productCode+=orderGood.goodsCode+",";
										body += (orderGood.goodsRemark != null && orderGood.goodsRemark != "") ? orderGood.goodsRemark + "," : "";
										totalAmout += orderGood.goodsBuyPrice;
									}
									this.axios({
										method: 'POST',
										url: "/v3/weixin/pay/weixinH5Pay",
										params: {
											"outTradeNo": orderCode,
											"totalFee": totalAmout,
											"body": subject.substring(0, subject.length - 1),
											"detail": ((body != "") ? body.substring(0, body.length - 1) : body),
											"notifyUrl": notifyUrl,
											"weixinCode": weixinCode,
										},
										data: {}
									}).then((res) => {
										window.location.href = rootUrl + "#/orderList"
									}).catch((err) => {
										Toast({
											message: err.response.data,
											iconClass: 'fontSize iconfont icon-shibai'
										});
										window.location.href = rootUrl + "#/orderList"
									});
								}
							});
						}
					}
				}
			},
      alipayPaymentResult(){
		 		this.axios({
		          method: 'post',
		          url: "/v3/alipay/pay/payResultReturnUrl",
		          data: {
		          }
		        }).then((res) => {
//		            this.fundMerchantSet.list = res.data.list;
//		            this.fundMerchantSet.pageTools = res.data.pageTools;
//		            this.fundMerchantSet.sumInfo = res.data.sumInfo;
//		            this.fundMerchantSet.pageTools.pageSizeOptions = JSON.parse(this.fundMerchantSet.pageTools.pageSizeOptions);
		        }).catch((err)=>{
					this.Public.openError(this,err.response.data);
				});
      }
		},
		created() {

		},
		mounted() {
			//this.weixinPayment();
		},
		activated() {
			document.querySelector('#vue_id_title').innerHTML = "我的订单";
			this.tabName = localStorage.getItem("orderName");
			if(!localStorage.getItem("orderName")) {
				this.tabName = "name1";
			}
		}
	}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
	.font_bold {
		font-weight: bold;
	}

	.inside_header {
		height: 1.2rem;
	}

	.content {
		background: #fff;
    margin-bottom: 1.6rem;
	}
</style>
